const app = getApp();
Page({
  data: {
    placeholder1: true,
    placeholder2: true,
    placeholder3: true,
    focus1: false,
    focus2: false,
    focus3:false,
  },
  onLoad: function (options) {
    this.setData({
      code: options.code,
      securityCode: options.securityCode
    })
  },
  toNext: function (e) {
    console.log(e.detail.value);
    this.setNewPay(e)
  },
  getPwd:function(e){
    this.setData({
      loginpwd: e.detail.value
    })
  },
  // 得到旧的支付密码
  getpwd: function (e) {
    if (e.detail.value.length == 6) {
      this.setData({
        pwd1: e.detail.value
      })
    }
  },
  // 得到支付密码
  getpwd1: function (e) {
    if (e.detail.value.length == 6) {
      this.setData({
        pwd2: e.detail.value
      })
      //wx.hideKeyboard();
    }
  },
  // 确定支付密码
  getpwd2: function (e) {
    if (e.detail.value.length == 6) {
      this.setData({
        testPwd: e.detail.value
      })
      //wx.hideKeyboard();
    }
  },
  // 支付密码
  setNewPay: function (e) {
    const _this = this;
    if (this.data.pwd2 != '' && this.data.testPwd != '') {
      if (this.data.pwd2 === this.data.testPwd) {
        wx.request({
          url: app.globalData.path + 'services/app/applets/SetPayPassWord',
          data: {
            password: _this.data.loginpwd,
            payPassword: _this.data.pwd2,
            code: _this.data.code,
            securityCode: _this.data.securityCode
          },
          method: 'POST',
          header: {
            'content-type': 'application/json', // 默认值
            'Authorization': 'Bearer ' + app.globalData.authorization
          },
          success: function (res) {
            console.log(res.data);
            if (res.data.success) {
              console.log('修改成功')
              wx.showToast({
                title: '修改成功',
                icon: 'success',
                duration: 2000
              })
              wx.switchTab({
                url: '../my/my',
              })
            } else {
              wx.showToast({
                title: res.data.error.message,
                icon: 'none',
                duration: 2000
              })
            }
          }
        })
      } else {
        wx.showModal({
          content: '两次密码不同',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              // console.log('用户点击确定')
            }
          }
        });
      }
    } else {
      wx.showModal({
        content: '密码不能为空',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            // console.log('用户点击确定')
          }
        }
      });
    }
  },
  placeholder1:function(){
    this.setData({
      placeholder1: false,
      focus1:true
    })
  },
  blur1:function(){
    if (this.data.pwd1.length == 0) {
      this.setData({
        placeholder1: true,
        focus1: false
      })
    }
  }
})